home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / kwizard.h.z / kwizard.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  10.0 KB  |  350 lines

  1. /*  This file is part of the KDE Libraries
  2.     Copyright (C) 1998 Thomas Tanghus (tanghus@earthling.net)
  3.  
  4.     This program is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.     Boston, MA 02111-1307, USA.
  18. */  
  19.  
  20. #ifndef __KWIZARD_H
  21. #define __KWIZARD_H
  22.  
  23. #include <kapp.h>
  24. #include <qpopmenu.h>
  25. #include <qlabel.h>
  26. #include <qaccel.h>
  27. #include <qfont.h>
  28. #include <qpushbt.h>
  29. #include <qpainter.h>
  30. #include <qpen.h>
  31. #include <kdbtn.h>
  32. #include <kseparator.h>
  33. struct KWizProtected;
  34.  
  35. /**
  36. * KWizardPage holds information about the pages in the wizard. Given as
  37. * argument to @ref addPage.
  38. */
  39. struct KWizardPage
  40. {
  41.   QString title;
  42.   QWidget *w;
  43.   bool enabled;
  44.   int id;
  45. };
  46.  
  47.  
  48. #define NEXT klocale->translate("&Next >>")
  49. #define PREV klocale->translate("<< &Previous")
  50.  
  51.  
  52. /**
  53. * KWizard is a multi-purpose dialog. It is very useful for:
  54. *
  55. * - Configuration dialogs where the order in which the entries are filled is important.
  56. *
  57. * - Tutorials. Just create some HTML-widgets and feed them to a KWizard and your done (almost).
  58. *
  59. * - NoteBooks. KWizard is an integrated part of KNoteBook which provides a notebook
  60. *   dialog similar to the ones in OS/2 Warp 4.
  61. *
  62. * - Propably many other things...
  63. *
  64. * The dialog contains:
  65. *
  66. * - A title at the top of the page.
  67. *
  68. * - A separator.
  69. *
  70. * - The userprovided page-widget.
  71. *
  72. * - A separator.
  73. *
  74. * - A label indicating the pagination.
  75. *
  76. * - A Previous and a Next button.
  77. *
  78. * - Optionally Ok, Cancel and Help buttons.
  79. * @short KWizard
  80. * @author Thomas Tanghus <tanghus@earthling.net>
  81. * @version 0.1
  82. */
  83. class KWizard : public QWidget
  84. {
  85. friend class KNoteBook;
  86.     Q_OBJECT
  87.  
  88. public:
  89. /**
  90. * Constructor
  91. */
  92.     KWizard(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0);
  93. /**
  94. * Destructor
  95. */
  96.     ~KWizard();
  97. /**
  98. * Adds a page to the wizard.
  99. * The pages are numbered from 0-n where 0 is the page first added and n is the
  100. * page last added.
  101. * @param p KWizardPage containing the page data.
  102. *
  103. * @return Returns the id of the new page.
  104. */
  105.         int addPage(KWizardPage *p);
  106. /**
  107. * En/disable a specified page. If a page is disable its content will be grayd out
  108. * and it will not receive keyboard input.
  109. * @param page The page to en/disable.
  110. * @param state If 'state' is false the page will be disabled, otherwise it will be enabled.
  111. * @see KNoteBook#setPageEnabled
  112. */
  113.         void setPageEnabled(int page, bool state);
  114. /**
  115. * Check the state of the page.
  116. * @see #setPageEnabled
  117. * @return Returns true if the page is enabled, otherwise false.
  118. */
  119.         bool isPageEnabled(int page) { return pages->at(page)->enabled; };
  120. /**
  121. * Adds a Cancel button to the bottom of the dialog. The text will be a translated
  122. * version of the string '&Cancel' thereby giving it the shortcut key 'c'.
  123. * If any buttons are added a space will be created at the bottom of the dialog
  124. * to fit the buttons. When clicked the button will emit the @ref cancelclicked signal.
  125. * @see KLocale#translate
  126. */
  127.         void setCancelButton();
  128. /**
  129. * Adds a Cancel button to the bottom of the dialog.
  130. * @param text A user supplied text to write to the button.
  131. */
  132.         void setCancelButton(const char *text);
  133. /**
  134. * Adds a Default button to the bottom of the dialog. The text will be a translated
  135. * version of the string '&Default' thereby giving it the shortcut key 'd'.
  136. * If any buttons are added a space will be created at the bottom of the dialog
  137. * to fit the buttons. When clicked the button will emit the @ref defaultclicked signal.
  138. * @see KLocale#translate
  139. */
  140.         void setDefaultButton();
  141. /**
  142. * Adds a Default button to the bottom of the dialog.
  143. * @param text A user supplied text to write to the button.
  144. */
  145.         void setDefaultButton(const char *text);
  146. /**
  147. * Adds a Help button to the bottom right of the dialog. The text will be a translated
  148. * version of the string '&Help' thereby giving it the shortcut key 'h'.
  149. * If any buttons are added a space will be created at the bottom of the dialog
  150. * to fit the buttons. When clicked the button will emit the @ref helpclicked signal.
  151. * @see #getHelpButton
  152. */
  153.         void setHelpButton();
  154. /**
  155. * Adds a Help button to the bottom of the dialog. This button will generate the
  156. * signal @ref helpclicked where the int is the page to which the help was requested.
  157. * @see #getHelpButton
  158. * @param text A user supplied text to write to the button.
  159. */
  160.         void setHelpButton(const char *);
  161. /**
  162. * Adds an Ok button to the bottom right of the dialog. The text will be a translated
  163. * version of the string '&Ok' thereby giving it the shortcut key 'o'.
  164. * If any buttons are added a space will be created at the bottom of the dialog
  165. * to fit the buttons. When clicked the button will emit the @ref okclicked signal.
  166. * @see #getOkButton
  167. */
  168.         void setOkButton();
  169. /**
  170. * Adds an Ok button to the bottom of the dialog. This button will generate the
  171. * signal @ref okclicked where the int is the page to which the help was requested.
  172. * @see #getOkButton
  173. * @param text A user supplied text to write to the button.
  174. */
  175.         void setOkButton(const char *);
  176. /**
  177. * @see #setOkButton
  178. * @return Returns the Ok buttonwidget or 0L if no button is added.
  179. */
  180.         QButton * getOkButton();
  181. /**
  182. * @see #setCancelButton
  183. * @return Returns the Cancel buttonwidget or 0L if no button is added.
  184. */
  185.         QButton * getCancelButton();
  186. /**
  187. * @see #setDefaultButton
  188. * @return Returns the Default buttonwidget or 0L if no button is added.
  189. */
  190.         QButton * getDefaultButton();
  191. /**
  192. * @see #setHelpButton
  193. * @return Returns the Help buttonwidget or 0L if no button is added.
  194. */
  195.         QButton * getHelpButton();
  196. /**
  197. * getNextButton.
  198. * @return Returns the Next buttonwidget.
  199. */
  200.         QButton * getNextButton();
  201. /**
  202. * getPreviousButton
  203. * @return Returns the Previous buttonwidget.
  204. */
  205.         QButton * getPreviousButton();
  206. /**
  207. * @see #setEnableArrowButtons
  208. * @return Returns the left arrowbutton.
  209. */
  210.         KDirectionButton * getLeftArrow();
  211. /**
  212. * @see #setEnableArrowButtons
  213. * @return Returns the right arrowbutton.
  214. */
  215.         KDirectionButton * getRightArrow();
  216. /**
  217. * Let direction buttons reflect page.
  218. * @see #directionsReflectsPage
  219. * @param state If state is true the direction buttons (Previous and Next) will have the
  220. * title of the corresponding page.
  221. */
  222.         void setDirectionsReflectsPage(bool state);
  223. /**
  224. * @return Returns whether the direction buttons reflects the title of the corresponding page.
  225. *
  226. * @see #setDirectionsReflectsPage(bool state)
  227. */
  228.         bool directionsReflectsPage();
  229. /**
  230. * En/Disable the popup menu.
  231. * @see #enablePopupMenu
  232. * @param state If state is true a menu containing the pages in the wizard
  233. * will popup when the user RMB-clicks on the page-title.
  234. */
  235.         void setEnablePopupMenu(bool state);
  236. /**
  237. * @see #setEnablePopupMenu
  238. * @return Returns 'true' if the popupmenu is enabled.
  239. */
  240.         bool enablePopupMenu();
  241. /**
  242. * getMenu
  243. * @see #setEnablePopupMenu #enablePopupMenu
  244. * @return Returns the handle of the popup menu.
  245. */
  246.         QPopupMenu * getMenu();
  247. /**
  248. * En/Disable the arrow buttons at the rightmost of the title.
  249. * @param state If state is true two arrows will appear to the right of the pagination
  250. * allowing the user to change pages by clicking on them.
  251. * @see #enableArrowButtons
  252. */
  253.         void setEnableArrowButtons(bool state);
  254. /**
  255. * @see #setEnableArrowButtons
  256. * @return Returns 'true' if the arrow buttons are enabled.
  257. */
  258.         bool enableArrowButtons();
  259.         QSize sizeHint() { return minimumSize(); };
  260.         void adjustSize() { resize(sizeHint()); };
  261. /**
  262. * getTitle
  263. * @return Returns the title of a specified page. Used by KNoteBook
  264. * @param page The page to retrieve the title from.
  265. */
  266.         const char * getTitle(int page) { return pages->at(page)->title.data(); };
  267. /**
  268. * numPages
  269. * @return Returns the number of pages in the wizard.
  270. */
  271.         int numPages();
  272.  
  273. signals:
  274. /**
  275. * This signal is emitted when the user clicks on the Ok button.
  276. */
  277.         void okclicked();
  278. /**
  279. * This signal is emitted when the user clicks on the Cancel button.
  280. */
  281.         void cancelclicked();
  282. /**
  283. * This signal is emitted when the user clicks on the Default button.
  284. * The int is the page which was showing when default settings was requested.
  285. */
  286.         void defaultclicked(int);
  287. /**
  288. * This signal is emitted when the user clicks on the Help button.
  289. * The int is the page which was showing when help was requested.
  290. * @see #setHelpButton
  291. * <BR>
  292. * @see #getHelpButton
  293. */
  294.         void helpclicked(int);
  295. /**
  296. * This signal is emitted when a page is selected. The int is the page number
  297. */
  298.         void selected(int);
  299.  
  300. /**
  301. * This signal is emitted when the dialog is closed. Mainly usable if the dialog
  302. * is a top level widget.
  303. */
  304.         void closed();
  305.  
  306. /**
  307. * This signal is emitted when a popup menu is requested. This happens when the user
  308. * RMB-clicks somewhere in the title (not the titlebar). This is used by KNoteBook.
  309. */
  310.         void popup(QPoint);
  311. /**
  312. * This signal is used by KNoteBook.
  313. */
  314.         void nomorepages(bool, bool);
  315.  
  316. public slots:
  317. /*
  318. * Goto to a specified page.
  319. * @param page The page number to turn to.
  320. */
  321.         void gotoPage(int page);
  322.  
  323. protected slots:
  324.         void nextPage();
  325.     void previousPage();
  326.     void okClicked();
  327.     void cancelClicked();
  328.     void defaultClicked();
  329.         void helpClicked();
  330.  
  331. protected:
  332.         bool eventFilter( QObject *, QEvent * );
  333.         void closeEvent(QCloseEvent *);
  334.  
  335.         QSize pageSize();
  336.         void setSizes();
  337.         void resizeEvent(QResizeEvent *);
  338.         void paintEvent(QPaintEvent *);
  339.  
  340.         QList<KWizardPage> *pages;
  341.         //QList<QWidget> pages;
  342.         //QStrList titles;
  343.         KWizProtected *pwiz;
  344. };
  345.  
  346. #endif // __KWIZARD_H
  347.  
  348.  
  349.